package ru.nnstu.medialib.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import ru.nnstu.medialib.domain.Author;

public class AuthorDAOImpl implements AuthorDAO {

	@Override
	public void saveAuthor(Author author) {
		Session session = HibernateUtil.getSession();
		Transaction tr = session.beginTransaction();
		session.save(author);
		tr.commit();
	}

	@Override
	public List<Author> listAuthor() {
		Session session = HibernateUtil.getSession();
		Criteria crit = session.createCriteria(Author.class);
		return crit.list();
	}

	@Override
	public void removeAuthor(Long id) {
		Session session = HibernateUtil.getSession();
		Object obj = session.load(Author.class, id);
		session.delete(obj);
	}

}
